﻿using System;
using System.Collections.Generic;
using System.Text;

using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;

using ISS.CaseStudy.DBUtility;
using ISS.CaseStudy.Entities;

namespace ISS.CaseStudy.DAL
{
    public static class CaseStudyRelatedInfoDLL
    {
        public static DataSet GetAllInfos()
        {
            string sql = "select * from CaseStudyRelatedInformation";
            DataSet dataSet = Database.SpExecuteDataSet(sql);
            return dataSet;
        }

        public static DataSet GetInfosByCaseStudyId(string caseStudyId)
        {
            string sql = "select * from CaseStudyRelatedInformation where [CaseStudyId]=@CaseStudyid";
            SqlParameter[] paramCollection = { new SqlParameter("@CaseStudyid", caseStudyId) };
            return Database.SpExecuteDataSet(sql, paramCollection);
        }

        public static DataSet GetInfosByRelatedId(string relatedId)
        {
            string sql = "select * from CaseStudyRelatedInformation where [RelatedId]=@RelatedId";
            SqlParameter[] paramCollection = { new SqlParameter("@RelatedId", relatedId) };
            return Database.SpExecuteDataSet(sql, paramCollection);
        }

        public static bool Insert(CaseStudyRelatedInfo caseStudyRelatedInfo)
        {
            bool b = false;
            string sql = "insert into CaseStudyRelatedInformation([CaseStudyId],[RelatedId]) values (@CaseStudyId,@RelatedId)";
            SqlParameter[] paramCollection = { new SqlParameter("@CaseStudyId", caseStudyRelatedInfo.CaseStudyId),  
                                                 new SqlParameter("@RelatedId", caseStudyRelatedInfo.RelatedId) };
            int i = Database.SpExecuteNonQuery(sql, paramCollection);
            if (i > 0)
            {
                b = true;
            }
            return b;
        }

        public static bool DeleteByCaseStudyId(string caseStudyId)
        {
            bool b = false;
            string sql = "delete from CaseStudyRelatedInformation where ([CaseStudyId]=@CaseStudyId)";
            SqlParameter[] paramCollection = { new SqlParameter("@CaseStudyId", caseStudyId) };
            int i = Database.SpExecuteNonQuery(sql, paramCollection);
            if (i > 0)
            {
                b = true;
            }
            return b;
        }

        public static bool DeleteByRelatedId(string relatedId)
        {
            bool b = false;
            string sql = "delete from CaseStudyRelatedInformation where ([RelatedId]=@RelatedId)";
            SqlParameter[] paramCollection = { new SqlParameter("@RelatedId", relatedId) };
            int i = Database.SpExecuteNonQuery(sql, paramCollection);
            if (i > 0)
            {
                b = true;
            }
            return b;
        }
    }
}
